#include <bits/stdc++.h>

#define width 1080
#define height 1080
using namespace std;

struct Node {
    bool color = 0;
    bool already = 0; 
    Node *next = nullptr;
    Node *goingnext = nullptr;
    int x;
    int y;
};

Node* vertex[width][height];
int mat[width][height];

void GoingMat(Node* mat) {
    Node* t = mat;
    while(t != nullptr) {
        if(t->color && !(t->already)) {
            Node* p = t;
            while(p && !(p->already)) {
                cout << p->x << ',' << p->y << ',';
                p->already = 1;
                p = p->next;
            }
        }
        t = t->goingnext;
    }
}

int main() {
    int rows;
    int cols;
    cin >> rows;
    cin >> cols;
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < cols; j++) {
            cin >> mat[i][j];
            vertex[i][j] = new Node;
            vertex[i][j]->x = i;
            vertex[i][j]->y = j;
            if(mat[i][j]) {
                vertex[i][j]->color = 1;
            }
        }
    }

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < cols; j++) {
            ////cerr << "visited1" << endl;
            if(j < cols - 1) {
                vertex[i][j]->goingnext = vertex[i][j+1];
                
            }
            else if(i < rows - 1) {
                vertex[i][j]->goingnext = vertex[i+1][0];
            } 
            //else vertex[i][j]->goingnext = nullptr;
            if(vertex[i][j]->color) {
                ////cerr << "visted2" << endl;
                if(i > 0 && i < rows - 1) {
                    if(j > 0 && j < cols - 1) {
                        //cerr << "visited1" << endl;
                        for(int m = -1; m <= 1; m++)
                            for(int n = -1; n <= 1; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                    else if(j == 0) {
                        //cerr << "visited2" << endl;
                        for(int m = -1; m <= 1; m++)
                            for(int n = 0; n <= 1; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                    else if(j == cols - 1) {
                        //cerr << "visited3" << endl;
                        for(int m = -1; m <= 1; m++)
                            for(int n = -1; n <= 0; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                }
                else if (i == 0) {
                    if(j > 0 && j < cols - 1) {
                        //cerr << "visited4" << endl;
                        for(int m = 0; m <= 1; m++)
                            for(int n = -1; n <= 1; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                    else if(j == 0) {
                        //cerr << "visited5" << endl;
                        for(int m = 0; m <= 1; m++)
                            for(int n = 0; n <= 1; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                    else if(j == cols - 1) {
                        //cerr << "visited0" << endl;
                        for(int m = 0; m <= 1; m++)
                            for(int n = -1; n <= 0; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                }
                else if (i == rows - 1) {
                    if(j > 0 && j < cols - 1) {
                        //cerr << "visited6" << endl;
                        for(int m = -1; m <= 0; m++)
                            for(int n = -1; n <= 1; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                    else if(j == 0) {
                        //cerr << "visited7" << endl;
                        for(int m = -1; m <= 0; m++)
                            for(int n = 0; n <= 1; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                    else if(j == cols - 1) {
                        //cerr << "visited8" << endl;
                        for(int m = -1; m <= 0; m++)
                            for(int n = -1; n <= 0; n++){
                                if(vertex[i+m][j+n]->color && !(m == n || m == n + 2 || n == m + 2)) {
                                    vertex[i][j]->next = vertex[i+m][j+n];
                                    //break;
                                }
                            }
                    }
                }
            }
        }
    }
    GoingMat(vertex[0][0]); 
}